Passed
Push — main ( 3c9e73...288e05 )
by Andrii
01:55
created

toggling.spec.tsx ➔ Component   A

Complexity

Conditions 1

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
import React from "react"
2
import type { ClassNames, ClassNamesProperty, ClassHash } from "."
3
import classNaming, { classNamesCheck } from "."
4
import expectRender from "../expect-to-same-render"
5
6
const {classnames}: ClassNames<typeof App> = {
7
  classnames: {
8
    "App__Item": "hash",
9
    class1: "hash1",
10
    class2: "hash2"
11
  }
12
}
13
14
function App({classnames, className}: ClassNames<
15
  true,
16
  ClassNamesProperty<{App__Item: ClassHash}>,
17
  typeof Component
18
  >) {
19
  return <Component {...{
20
    ...classNaming({
21
      classnames, className
22
    })(
23
      true, {App__Item: true}
24
    ),
25
    classnames
26
  }}/>
27
}
28
29
//TODO No rename inheritance
30
function Component(props: ClassNames<true, {classnames: {class1: ClassHash, class2: ClassHash}}>) {
31
  const classes = classNaming(props)
32
  return <>
33
    <div {...classes(true, {class1: true, class2: false})}/>
34
    <div {...classes({class2: true})}/>
35
  </>
36
}
37
38
describe(classNaming.name, () => {
39
  it("not module", () => expectRender(
40
    <App className="MyApp" classnames={classNamesCheck()} />
41
  ).toSame(
42
    <div className="MyApp App__Item class1" />,
43
    <div className="class2" />
44
  ))
45
46
  it("css module", () => expectRender(
47
    <App className="MyApp" classnames={classnames} />
48
  ).toSame(
49
    <div className="MyApp hash hash1" />,
50
    <div className="hash2" />
51
  ))
52
53
  it("not propagate classnames", () => {
54
    const App = ({classnames, className}: ClassNames<
55
      true,
56
      ClassNamesProperty<{App__Item: ClassHash}>,
57
      typeof Component>
58
    ) =>
59
      //@ts-expect-error Types of property classnames are incompatible Type undefined is not assignable 
60
      <Component {
61
        ...classNaming({
62
          classnames, className
63
        })(
64
          true, {App__Item: true}
65
        )}
66
      />
67
    
68
    expectRender(
69
      <App className="MyApp" classnames={classnames}/>
70
    ).toSame(
71
      <div className="MyApp hash class1" />,
72
      //TODO split wrong usage
73
      <div className="MyApp hash class2" />  
74
    )
75
  })
76
})
77